﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;

namespace Automobile.service.UI
{
    public partial class AddBliTem : System.Web.UI.Page
    {
        BlitemBll bll = new BlitemBll();
        WareHoseBll wbll = new WareHoseBll();
        ProductBll pbll = new ProductBll();
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
                LoadPro();
                LoadType();
            }
           
        }

        private void LoadType()
        {
            this.DropDownList3.DataSource =bll.Blitem_type();
            this.DropDownList3.DataValueField = "Blitem_type_Id";
            this.DropDownList3.DataTextField = "Blitem_type_name";
            this.DropDownList3.DataBind();
        }

        private void LoadPro()
        {
            this.DropDownList2.DataSource = pbll.Product();
            this.DropDownList2.DataValueField = "Product_Id";
            this.DropDownList2.DataTextField = "Product_Name";
            this.DropDownList2.DataBind();
        }

        private void LoadData()
        {
            this.DropDownList1.DataSource = wbll.WareHose();
            this.DropDownList1.DataValueField = "WareHose_Id";
            this.DropDownList1.DataTextField = "WareHose_Name";
            this.DropDownList1.DataBind();
           
        }
       
        protected void BtnAdd(object sender, EventArgs e)
        {
            BlitemModel b = new BlitemModel();
          
               b.Blitem_Etc = this.TextBox3.Text.ToString();
               b.WareHose_Id =Convert.ToInt32( this.DropDownList1.SelectedValue);
               b.Blitem_date=Convert.ToDateTime(this.TextBox5.Text);
               b.Blitem_num =Convert.ToInt32(this.TextBox6.Text);
               b.Blitem_Rownum=Convert.ToInt32(this.TextBox7.Text);
               b.Blitem_Stock_num =Convert.ToInt32(this.TextBox8.Text);
               b.Product_Id = Convert.ToInt32(this.DropDownList2.SelectedValue);
               b.Blitem_Type_Id = Convert.ToInt32(this.DropDownList3.SelectedValue);
               if (bll.AddBlitem(b) > 0)
               {                  
                   Response.Write("<script>alert('添加成功');location.href='Blitem.aspx';</script>");
               }
               else
               {
                   Response.Write("<script>alert('添加失败!');</script>");
               }
        }

        protected void BtnBack(object sender, EventArgs e)
        {
            Response.Redirect("Blitem.aspx");
        }
    }
}